package org.wsalger.zm.zmbus;


import android.R.integer;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainInActivity extends Activity {
	private Button but1=null;
	private Button but2=null;
	private Button but3=null;
	private Button but4=null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		String quary;
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_mainin);
		
		but1=(Button)findViewById(R.id.but1);
		but2=(Button)findViewById(R.id.but2);
		but3=(Button)findViewById(R.id.but3);
		but4=(Button)findViewById(R.id.but4);
		
		but1.setVisibility(View.GONE);
		but2.setVisibility(View.GONE);
		but3.setVisibility(View.GONE);
		but4.setVisibility(View.GONE);
		
		but1.setOnClickListener(l);
		but2.setOnClickListener(l);
		but3.setOnClickListener(l);
		but4.setOnClickListener(l);	

		quary=(String) getIntent().getSerializableExtra("keyStr");
		
		for (int i = 0; i < quary.split("\\|").length; i++) {
			switch (Integer.valueOf(quary.split("\\|")[i])) {
			case 1:
				but1.setVisibility(View.VISIBLE);
				break;
			case 2:
				but2.setVisibility(View.VISIBLE);
				break;
			case 3:
				but3.setVisibility(View.VISIBLE);
				break;
			case 4:
				but4.setVisibility(View.VISIBLE);
				break;
			default:
				break;
			}
		}
	}
	
	private OnClickListener l=new OnClickListener() {
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Button b = (Button)v;
			//String buttonText = String.valueOf(b.getId());
			//Toast.makeText(MainInActivity.this,buttonText,Toast.LENGTH_SHORT).show();  
			
			Intent i=new Intent();
			switch (b.getId()) {
			case R.id.but1:
				i.setClass(MainInActivity.this,WeeklyActivity.class);
				break;
			case R.id.but2:
				i.setClass(MainInActivity.this,CommunisActivity.class);
				break;
			case R.id.but3:
				i.setClass(MainInActivity.this,PostActivity.class);
				break;
			case R.id.but4:
				i.setClass(MainInActivity.this,KnowledgeActivity.class);
				break;
			default:
				i.setClass(MainInActivity.this,MainActivity.class);
				break;
			}
			startActivity(i);
		}
	};

}
